package com.hjxy.controller;

import com.hjxy.pojo.Class1;
import com.hjxy.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description:
 * @author: ty
 * @createDate: 2020/10/4
 * @version: 1.0
 */
@Controller
@RequestMapping("/classroom")
public class ClassController {

    @Autowired
    private ClassService classroomService;

    @RequestMapping("/getClassroom")
    public String getClassroom(){
        return "class";
    }

    @RequestMapping("/queryClassroom")
    @ResponseBody
    public Map<String,Object> queryClassroom(){
        List<Class1> classrooms = classroomService.queryAllClassroom();
        Map<String,Object> result = new HashMap<>();
        result.put("code",0);
        result.put("message","成功");
        result.put("num",classrooms.size());
        result.put("classrooms",classrooms);
        return result;
    }

    @RequestMapping("/getAddClassroom")
    public String getAddClassroom(){
        return "class-add";
    }

    @RequestMapping("/insertClassroom")
    @ResponseBody
    public Map<String,Object> addClassroom(Class1 classroom){
        classroomService.addClassroom(classroom);
        Map<String,Object> result = new HashMap<>();
        result.put("code",0);
        result.put("message","成功");
        result.put("classroom",classroom);
        return result;
    }

    //修改
    @RequestMapping("/updateClass")
    public String updateClass(){
        return "class-update";
    }


    @RequestMapping("/deleteClassroom")
    @ResponseBody
    public Map<String,Object> deleteClassroomById(Integer classroomId){
        classroomService.deleteClassroomById(classroomId);
        Map<String,Object> result = new HashMap<>();
        result.put("code",0);
        result.put("message","成功");
        return result;
    }
}
